<div class="list">
    <?php echo form_open('foreign'); ?>
    <div class="search-div">
        <div>
            <label class="span-2">申请人</label>
            <input class="text span-5" type="text" name="c_name" value="<?php echo $conditions['c_name']; ?>" />
            <label class="span-2">案件类型</label>
            <?php 
                if (!empty($conditions['case_type'])) {
                    foreach ($conditions['case_type'] as $case_type) {
                        echo form_hidden('case_type[]', $case_type);
                    }
                }
                echo form_dropdown('', $case_types, $conditions['case_type'], 
                        'class="span-12 chosen-select" multiple id="case_type"');
            ?>
            <div class="clear"></div>
        </div>
        <div>
            <label class="span-2">商标/专利</label>
            <input class="text span-5" type="text" name="tm_name" value="<?php echo $conditions['tm_name']; ?>" />
            <label class="span-2">代理人</label>
            <?php 
                if (!empty($conditions['agent'])) {
                    foreach ($conditions['agent'] as $agent) {
                        echo form_hidden('agent[]', $agent);
                    }
                }
                echo form_dropdown('', $agents, $conditions['agent'], 
                        'class="span-12 chosen-select" multiple id="agent"');
            ?>
            <div class="clear"></div>
        </div>
        <div>
            <label class="span-2">指定国家</label>
            <input class="text span-5" type="text" name="c_country" value="<?php echo $conditions['c_country']; ?>" />
            <label class="span-2">合作所</label>
            <?php 
                if (!empty($conditions['partner'])) {
                    foreach ($conditions['partner'] as $partner) {
                        echo form_hidden('partner[]', $partner);
                    }
                }
                echo form_dropdown('', $partners, $conditions['partner'], 
                        'class="span-12 chosen-select" multiple id="partner"');
            ?>
            <div class="clear"></div>
        </div>
        <div>
            <label class="span-2">档案号</label>
            <input class="text span-5" type="text" name="file_no" value="<?php echo $conditions['file_no']; ?>" />
            <label class="span-2">建档日期</label>
            <input class="text span-3 normal-date" name="file_create_date_from" readonly="readonly"
                   value="<?php echo $conditions['file_create_date_from']; ?>" />
            <label class="span-1">至</label>
            <input class="text span-3 normal-date" name="file_create_date_to" readonly="readonly"
                   value="<?php echo $conditions['file_create_date_to']; ?>" />
            <button type="submit">查询</button>
            <button type="button" id="reset">重置</button>
            <button type="button" id="export">导出</button>
            <div class="clear"></div>
        </div>
    </div>
    </form>
    <hr class="space">
    <table>
        <tr>
            <th>档案号</th>
            <th>建档日期</th>
            <th>申请人</th>
            <th>商标/专利</th>
            <th>类别</th>
            <th>指定国家</th>
            <th>案件类型</th>
            <th>代理人</th>
            <th>合作所</th>
            <th class="align-right">总费用</th>
            <th>是否收款</th>
            <th width="10%">操作</th>
        </tr>
        <?php foreach ($foreigns as $f): ?>
        <tr>
            <td><?php echo $f['file_no']; ?></td>
            <td><?php echo $f['file_create_date']; ?></td>
            <td><?php echo $f['c_name']; ?></td>
            <td><?php echo $f['tm_name']; ?></td>
            <td><?php echo $f['tm_class']; ?></td>
            <td><?php echo $f['c_country']; ?></td>
            <td><?php echo $f['case_type']; ?></td>
            <td><?php echo $f['agent']; ?></td>
            <td><?php echo $f['partner']; ?></td>
            <td class="align-right"><?php echo number_format($f['total_fee'], 2); ?></td>
            <td><?php echo $f['is_collected']; ?></td>
            <td>
                <a href="<?php echo site_url('foreign/update/' . $f['f_id']); ?>">修改</a> | 
                <a href="<?php echo site_url('foreign/remove/' . $f['f_id']); ?>" 
                   onclick="return confirm('确定要删除档案 <?php echo $f['file_no']; ?> 吗？');">删除</a> |
                <a href="<?php echo site_url('foreign/view/' . $f['f_id']); ?>">查看</a>
            </td>
        </tr>
        <?php endforeach; ?>
    </table>
    <?php echo $pagelink; ?>
</div>
<script>
    $(function() {
        $("button").button();
        bindDatepicker("input.normal-date");
        $(".chosen-select").chosen();
        
        $(".chosen-select").on('change', function(event, params) {
            var element = event.target;
            if (params.selected) {
                $(element).before('<input type="hidden" name="' + element.id + '[]" value="' + params.selected + '" />');
            } else if (params.deselected) {
                $(element).siblings('input[type=hidden][value=' + params.deselected + ']').remove();
            }
        });
        
        $("#reset").on('click', function() {
            window.location.href = '<?php echo site_url('foreign'); ?>';
        });
        
        $("#export").click(function() {
            var action = this.form.action;
            this.form.action = '<?php echo site_url('foreign/export'); ?>';
            this.form.submit();
            this.form.action = action;
        });
    });
</script>